//
//  YCAppDelegate.m
//  LOLBox
//
//  Created by mac on 15-3-13.
//  Copyright (c) 2015年 Honey. All rights reserved.
//

#import "YCAppDelegate.h"
#import "YCTabView.h"
#import "YCVideoViewController.h"
#import "PublicUINav.h"
#import "YCNewViewController.h"
#import "YCHeros.h"
#import "YCLeagueInfo.h"
#import "YCMoreViewController.h"
#import "DataBaseSImple.h"
#import "WeiboSDK.h"
#import "WXApi.h"
#import <ShareSDK/ShareSDK.h>

@implementation YCAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    [self share];
    
    [self creatNavAndViewControllerAndTabBar];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    return YES;
}

//创建导航以及各种视图
- (void)creatNavAndViewControllerAndTabBar
{
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    YCNewViewController *news = [[YCNewViewController alloc] init];
    PublicUINav *navNews = [[PublicUINav alloc] initWithRootViewController:news];
    
    YCVideoViewController *video = [[YCVideoViewController alloc] init];
    PublicUINav *navVideo = [[PublicUINav alloc] initWithRootViewController:video];

    YCHeros *hero = [[YCHeros alloc] init];
    PublicUINav *navHero = [[PublicUINav alloc] initWithRootViewController:hero];
    
    YCLeagueInfo *leagueInfo = [[YCLeagueInfo alloc] init];
    PublicUINav *navLeagueInfo = [[PublicUINav alloc] initWithRootViewController:leagueInfo];

    YCMoreViewController *more = [[YCMoreViewController alloc] init];
    PublicUINav *navMore = [[PublicUINav alloc] initWithRootViewController:more];
    
    UITabBarController *tb = [[UITabBarController alloc] init];
    tb.viewControllers = @[navNews,navVideo,navHero,navLeagueInfo,navMore];
    tb.tabBar.hidden = YES;
    tb.selectedIndex = 0;
    
    self.tbBar = [[YCTabView alloc] initWithFrame:CGRectMake(0, self.window.bounds.size.height - 50, CGRectGetWidth([[UIScreen mainScreen] bounds]), 50)];
    [self.tbBar tranValue:^(NSInteger tag) {
        tb.selectedIndex = tag;
        
    }];
    [tb.view addSubview:self.tbBar];
    
    self.window.rootViewController = tb;

    //打开数据库
    [DataBaseSimple shareInstance];
}

- (void)hideTabBar
{
    self.tbBar.hidden = YES;
}
- (void)showTabBar
{
    self.tbBar.hidden = NO;
}
//分享
- (void)share
{
    //1.初始化ShareSDK应用,字符串"iosv1101"是应该换成你申请的ShareSDK应用中的Appkey
    [ShareSDK registerApp:@"6a37c2ada713"];
    
    //2. 初始化社交平台
    //2.1 代码初始化社交平台的方法
    [self initializePlat];
}

- (BOOL)application:(UIApplication *)application
      handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                        wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:self];
}

- (void)initializePlat
{
    /**
     连接新浪微博开放平台应用以使用相关功能，此应用需要引用SinaWeiboConnection.framework
     http://open.weibo.com上注册新浪微博开放平台应用，并将相关信息填写到以下字段
     **/
    [ShareSDK connectSinaWeiboWithAppKey:@"1243437096"
                               appSecret:@"a4d19dc65ae1859d111ed9004714a3dc"
                             redirectUri:@"https://api.weibo.com/oauth2/default.html"];
    
    //连接短信分享
    [ShareSDK connectSMS];

    /**
     连接微信应用以使用相关功能，此应用需要引用WeChatConnection.framework和微信官方SDK
     http://open.weixin.qq.com上注册应用，并将相关信息填写以下字段
     **/
    [ShareSDK connectWeChatWithAppId:@"wx26435f86d1fbd344"
                           appSecret:@"f02ba3f3203dc41c645bcd507d65fc87"
                           wechatCls:[WXApi class]];
    
    //连接邮件
    [ShareSDK connectMail];
    
    //连接拷贝
    [ShareSDK connectCopy];
}


@end
